<?php

namespace app\api\model;

use think\Model;

class Activity extends BaseModel
{
    protected $hidden = ['delete_time'];
    public function user()
    {
        return $this->hasOne('User', 'id', 'user_id');
    }

    public static function getActivityById($id)
    {
        $activity = self::with('user')
            ->find($id);

//         $banner = BannerModel::relation('items,items.img')
//             ->find($id);
        return $activity;
    }

    public function getByUid($id, $paginate = true, $page = 1, $size = 30)
    {
        $query = self::
        where('user_id', '=', $id);
        if (!$paginate)
        {
            return $query->select();
        }
        else
        {
            // paginate 第二参数true表示采用简洁模式，简洁模式不需要查询记录总数
            return $query->paginate(
                $size, true, [
                'page' => $page
            ]);
        }
    }

}